<?php
namespace App\Api\V1\Models;

use Illuminate\Database\Eloquent\Model;

class Message extends Model
{
     /*
     * 添加一个消息
     * */
    protected $table = 'message';
    public $timestamps = false;
    public function addMessageItem()
    {
        $data = [
            "type"=> "email",
            "member"=>"2",
            "title"=>"杀人猪心",
            "content"=>"姜文戴的是九筒面罩，杀的是黄四郎",
            "url"=>"www.baidu.com",
            "target"=>"_blank",
            "is_top"=>"0",
            "status"=>"1",
            "create_time"=>date("Y-m-d H:i:s",time()),
            "update_time"=>date("Y-m-d H:i:s",time()),
            "message_id"=>"8",
        ];
        $me = new Message();
        $me->type = $data['type'];
        $me->member = $data['member'];
        $me->title = $data['title'];
        $me->content = $data['content'];
        $me->url = $data['url'];
        $me->target = $data['target'];
        $me->is_top = $data['is_top'];
        $me->status = $data['status'];
        $me->create_time = $data['create_time'];
        $me->update_time = $data['update_time'];
        $me->message_id = $data['message_id'];
        $res = $me->save();
        if($res)
        {

                return $this->get()->toArray();

        }
        else{
            return '添加失败';
        }
    }
    /*
     * 编辑一个消息
     */
    public function setMessageItem()
    {
        $data =[
            "type" => "email",
            "member" => "2",
            "title" => "勇敢",
            "content" => "她一直都这么勇敢吗，她不知道我会武功吗",
            "url" => "www.baidu.com",
            "target" => "_blank",
            "is_top" => "0",
            "status" => "1",
            "create_time" => date("Y-m-d H:i:s", time()),
            "update_time" => date("Y-m-d H:i:s", time()),
            "message_id" => "8",
        ];
        $res = Message::where('message_id','8')->update($data);
        if ($res)
        {
            return $this->toArray();
        }
        return false;
    }
    public function setMessageStatus()
    {
        return $this->where('message_id','8')->delete();
    }
    public function getMessageItem()
    {
        return $this->where('message_id','8')->delete();
    }
    public function setMessageStatus()
    {
        return $this->where('message_id','8')->delete();
    }
}
